
from tkinter import *
app = Tk()
app.title("模拟登录系统")
app.geometry("900x380+300+150")

# 頁腳信息
copyright_lable = Label(app,text='廣雅中學 @ copyright')
copyright_lable.pack(side='bottom')

# 添加圖片
pic = r'C:/Users/a/Desktop/test01.gif'
canvas = Canvas(app)
image_file = PhotoImage(file=pic)
image = canvas.create_image(0,0,anchor='nw',image=image_file)
canvas.place(x=0,y=0,height=360, width=619)

# 登錄頁面提示信息
lp_title = Label(app,text='模拟登录页面',font=("Arial Black",22),fg='#32cd99')
lp_title.place(x=625,y=150)


# 用戶名輸入框
name_text = Variable()
name_lb = Label(app,text='用户名：',font=('微软雅黑',13))
name_lb.place(x=625,y=200)
name_input = Entry(app,textvariable=name_text,width=20)
name_input.place(x=685,y=200)

# 密碼輸入框
pwd_text = Variable()
pwd_lb = Label(app,text='密码：',font=('微软雅黑',13))
pwd_lb.place(x=625,y=235)
pwd_input = Entry(app,width=20,textvariable=pwd_text)
pwd_input.place(x=685,y=235)

# 登錄邏輯驗證
def login_func():
    msg = ''
    if name_text.get() == "":
        msg = "用户名不能为空".center(20, "=")
    elif pwd_text.get() == "":
        msg = "密码不能为空".center(20, "=")
    # elif pwd_text.get()!="" and name_text.get()!="":
    #     msg = "登陆成功"
    elif pwd_text.get()!="111111" and name_text.get()!="admin":
        msg = "用户名或密码错误".center(20, "=")
    elif pwd_text.get()=="111111" and name_text.get()=="admin":
        msg = "登录成功".center(20, "=")
    else:
        msg = ""
    pwd_lb = Label(app,text=msg,font=('微软雅黑',11),fg='red')
    pwd_lb.place(x=685, y=265)

# 登錄按鈕
login_button = Button(app,text='登陆',font=('微软雅黑',12),command=login_func)
login_button.place(x=770,y=280)

# 退出按鈕
quit_button = Button(app,text='退出',font=('微软雅黑',12),command=app.quit)
quit_button.place(x=700,y=280)

app.mainloop()